package summary;

import java.util.*;

/**
 * @Author: 海琳琦
 * @Date: 2022/4/18 11:51
 * https://leetcode-cn.com/problems/employee-importance/
 */
public class Title690 {

    class Employee {
        int id;
        int importance;
        List<Integer> subordinates;
    }

    public int getImportance(List<Employee> employees, int id) {
        Map<Integer, Employee> hash = new HashMap<>();
        for (Employee e : employees) {
            hash.put(e.id, e);
        }
        LinkedList<Employee> queue = new LinkedList<>();
        queue.offer(hash.get(id));
        int count = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                Employee people = queue.poll();
                count += people.importance;
                for (Integer peopleId : people.subordinates) {
                    queue.offer(hash.get(peopleId));
                }
            }
        }
        return count;
    }


    public static void main(String[] args) {

    }
}
